package de.mekos.shop.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import de.mekos.shop.connection.DatabaseConnection;
import de.mekos.shop.model.Performance;

/**
 * Zusammengestellte Ausstattungen auslesen
 * @author popa
 */
public class PerformanceDAO {

	public static Performance getById(int id) {
		Performance perf = new Performance();
		
		Connection conn = DatabaseConnection.getConnection();

		try {
			Statement stmt = conn.createStatement();

			String sql = "SELECT * FROM Ausstattung WHERE ID=" + id;
			ResultSet rs = stmt.executeQuery(sql);

			try {
				if (rs.next()) {
					perf.setId(rs.getInt(1));
					perf.setCpu(HardwareDAO.get("Cpu", rs.getInt(2)));
					perf.setHdd(HardwareDAO.getHdd(rs.getInt(3)));
					perf.setGrafic(HardwareDAO.get("Grafik", rs.getInt(4)));
					perf.setRam(HardwareDAO.get("Ram", rs.getInt(5)));
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		} 
		
		return perf;
	}

}
